home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbrowser / vbrowser.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-10-20  |  6.6 KB  |  202 lines

  1. VERSION 2.00
  2. Begin Form browserfrm 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "VBrowser"
  5.    ClientHeight    =   5835
  6.    ClientLeft      =   1140
  7.    ClientTop       =   2130
  8.    ClientWidth     =   7365
  9.    Height          =   6240
  10.    Left            =   1080
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5835
  13.    ScaleWidth      =   7365
  14.    Top             =   1785
  15.    Width           =   7485
  16.    Begin TextBox Text1 
  17.       Height          =   3735
  18.       Left            =   0
  19.       MousePointer    =   1  'Arrow
  20.       MultiLine       =   -1  'True
  21.       ScrollBars      =   3  'Both
  22.       TabIndex        =   3
  23.       Top             =   2040
  24.       Width           =   7335
  25.    End
  26.    Begin MsgBlaster MsgBlaster1 
  27.       Prop8           =   "Click on ""..."" for the About Box ---->"
  28.       Prop9           =   "Click on ""..."" for the Message Center --->"
  29.       Left            =   6000
  30.       MsgList         =   VBROWSER.FRX:0000
  31.       MsgPassage      =   VBROWSER.FRX:0064
  32.       TargetName      =   "browserfrm"
  33.       Top             =   600
  34.       UserMsgs        =   VBROWSER.FRX:0096
  35.       Version         =   "2.1a"
  36.    End
  37.    Begin CommandButton connbtn 
  38.       Caption         =   "&Connect"
  39.       Height          =   495
  40.       Left            =   3000
  41.       TabIndex        =   2
  42.       Top             =   600
  43.       Width           =   1695
  44.    End
  45.    Begin TextBox conntxt 
  46.       Height          =   285
  47.       Left            =   1200
  48.       TabIndex        =   0
  49.       Text            =   "http://"
  50.       Top             =   240
  51.       Width           =   5775
  52.    End
  53.    Begin Label url 
  54.       Height          =   255
  55.       Left            =   120
  56.       TabIndex        =   5
  57.       Top             =   1680
  58.       Width           =   7095
  59.    End
  60.    Begin Label Sockstatus 
  61.       Height          =   255
  62.       Left            =   120
  63.       TabIndex        =   4
  64.       Top             =   1200
  65.       Width           =   7215
  66.    End
  67.    Begin Label Label1 
  68.       Caption         =   "Connect:"
  69.       Height          =   255
  70.       Left            =   240
  71.       TabIndex        =   1
  72.       Top             =   240
  73.       Width           =   855
  74.    End
  75. Sub connbtn_click ()
  76. 'Ask for index.htm
  77. document$ = "/"
  78. call_server (Trim$(conntxt.Text))
  79. End Sub
  80. Sub conntxt_KeyPress (keyascii As Integer)
  81. If keyascii = 13 Then
  82.     connbtn_click
  83. End If
  84. End Sub
  85. Sub Form_Load ()
  86. status% = start_winsock()
  87. End Sub
  88. Sub Form_Unload (cancel As Integer)
  89. cancel = True
  90. quit_flag = True
  91. End Sub
  92. Sub MsgBlaster1_Message (msgval As Integer, wparam As Integer, lparam As Long, ReturnVal As Long)
  93. nodef = True    'No further message processing(for message blaster)
  94. 'wParam is handle, lParam=event
  95. 'SEE Winsock.txt
  96. 'NOTE NOTE NOTE NOTE
  97. 'Msgblast has a weirdness. To set the messages you want
  98. 'to trap, and the win handle, use the properties window
  99. 'for Msgblast. Click on 'message center'. If you LOOK at
  100. 'the message settings you may lose them. So if you lose
  101. 'the settings they are:
  102. 'Trap messages for 'browserfrm'
  103. 'Add user message 'EVENTMSG' (any name actually will do)
  104. 'number 8192.
  105. 'Add user message 'NAMEMSG' number 8193.
  106. 'Click the 'msg will be eaten' for both.
  107. 'wparam=namehandle when we made call
  108. 'lparam=any error code(hi word), event type (loword)
  109. 'Set globals so anybody can use
  110. event_type% = lparam And &HFFFF&
  111. event_error% = (lparam \ &H10000) And &HFFFF&
  112. event_wparam% = wparam
  113. If msgval = event_msg% Then
  114.     'Either got a close or a receive
  115.     If event_type% = FD_READ Then
  116.         'Received something, so read it
  117.         rxbuff$ = Space$(4096)
  118.         rxbufflen = Len(rxbuff$)
  119.         status% = recv(callsocket%, rxbuff$, rxbufflen, 0)
  120.         If status% = SOCKET_ERROR Then
  121.             status% = WSAGetLastError()
  122.             dprint "Read ERROR " + sockerror$(status%)
  123.         Else
  124.             rmsg$ = Left$(rxbuff$, status%)
  125.             If Len(current_msg$) = 0 Then
  126.                 'Start of msg
  127.                 current_msg$ = rmsg$
  128.             Else
  129.                 'next segment
  130.                 current_msg$ = current_msg$ + rmsg$
  131.             End If
  132.             dprint "Read " & Len(rmsg$) & " bytes."
  133.         End If
  134.     ElseIf event_type% = FD_CLOSE Then
  135.         'Got a close
  136.         'NOTE: Web servers will send the requested message and then
  137.         'disconnect. In theory, the received data should be received
  138.         'here BEFORE the connect is seen. i.e., our Winsock should receive
  139.         'all the data, send a receive message, and Then send the
  140.         'close message. Not so. Notice that sometimes you will get the
  141.         'close event message while their is still data to receive.
  142.         'By using a global closed status flag it appears that the data receive
  143.         'windows message will interrupt the main routine as soon as we exit
  144.         'the Msgblast routine, which throws us immediately back into the Msgblast
  145.         'receive data routine which the gets the data. It looks like the main
  146.         'recieve loop never gets a chance to recognize the closed flag. This is
  147.         'a bit too close for comfort and one should probably use the Winsock status
  148.         'call(s) to see if there is more data to be received before issuing a close
  149.         'socket. However, I have not missed any data yet. Wouldn't it be nice if
  150.         'Winsock specifications clearly explained what is happening?
  151.         dprint "Close received for socket " & wparam
  152.         'Set global flag
  153.         closed = True
  154.     End If
  155. ElseIf msgval = name_msg% Then
  156.     dprint "Name response received. lparam: " & Hex$(lparam) & "x " & lparam
  157.     got_name_response = True
  158. End If
  159. End Sub
  160. Sub Text1_Click ()
  161. ipt = text1.SelStart
  162. For i = ipt To 1 Step -1
  163.     c$ = Mid$(text1.Text, i, 1)
  164.     If c$ = "[" Then
  165.         flag = True
  166.         Exit For
  167.     ElseIf c$ = "]" Then
  168.         Exit For
  169.     End If
  170.     l$ = c$ + l$
  171. If flag Then
  172.     flag = False
  173.     For i = ipt + 1 To Len(text1.Text)
  174.         c$ = Mid$(text1.Text, i, 1)
  175.         If c$ = "]" Then
  176.             flag = True
  177.             Exit For
  178.         ElseIf c$ = "[" Then
  179.             Exit For
  180.         End If
  181.         l$ = l$ + c$
  182.     Next
  183. End If
  184. If flag Then
  185.     document$ = ""
  186.     delim = InStr(links$, l$)
  187.     If delim Then
  188.         For i = delim - 2 To 1 Step -1
  189.             c$ = Mid$(links$, i, 1)
  190.             If c$ = "]" Then
  191.                 Exit For
  192.             Else
  193.                 document$ = c$ + document$
  194.             End If
  195.         Next
  196.         If Len(document$) Then
  197.             call_server (Trim$(conntxt.Text))
  198.         End If
  199.     End If
  200. End If
  201. End Sub
  202.